let office_title = document.querySelector("#office-title");
let office_model = document.querySelector("#office-model");

office_title.addEventListener("mousedown", function (e) {
    let x = e.pageX - office_model.offsetLeft;
    let y = e.pageY - office_model.offsetTop;

    document.addEventListener("mousemove", move);
    function move(e) {
        office_model.style.left = e.pageX - x + 'px';
        office_model.style.top = e.pageY - y + 'px';
    }

    document.addEventListener("mouseup", function (e) {
        document.removeEventListener("mousemove", move);
    })
});


function show_office_model(dep_td_id) {
    document.getElementById("selection-office").style.display="table-row";
    document.getElementById('SummitDepBut').setAttribute("onclick", "summit_dep_val('"+dep_td_id+"')")
}

function close_office_models() {
    document.getElementById("selection-office").style.display = "none";
}

function check_dep_ff(ele_name, ele_id, flag=true) {
    var html_str = `
        <div id="selected-dep-`+ele_id+`" style="width: 95%;height: 30px;vertical-align: top;position: relative;background: #E8E8E8;margin-top: 8px;padding-left: 2%;line-height: 30px;">
            <div id="close" onclick="remove_dep(`+ele_id+`)" style="width: 15px;height: 15px;background: #cfcfcf;border-radius: 50%;line-height: 14px;cursor: pointer;">
                <i class="iconfont icon-quchu" style="font-size: 12px;color: white;margin-left: 1px;"></i>
            </div>
            <p class="selected-department" style="height: 15px;margin-top: 0;font-size: 14px;">`+ele_name+'('+ele_id+')'+`</p>
        </div>
    `

    if (flag) {
        check_more_one_not1(ele_id);
        document.getElementById('processed_prople').innerHTML = '';
    }

    if (!document.getElementById("dep-"+ele_id).checked){
        document.getElementById(ele_id).checked = false;
        document.getElementById('selected-dep-'+ele_id).remove();
    }else {
        $("#processed_prople").append(html_str)
    }
}

// checkBox�������ѡ
function check_more_one_not1(ele_id) {
    var check_box_list = document.getElementsByClassName("check_box1");
    for (var i = 0; i < check_box_list.length; i++) {
        if (String(check_box_list[i].id) !== String(ele_id)) {
            document.getElementById(check_box_list[i].id).checked = false;
        } else {
            document.getElementById(check_box_list[i].id).checked = true;
        }
    }
}

function remove_dep(obj_id) {
    document.getElementById('selected-dep-'+obj_id).remove();
    document.getElementById("dep-"+obj_id).checked = false;
}